package com.shop.cereshop.commons.enums;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * 店铺类型枚举
 */
public enum ShopTypeEnum{

    TONG_CHENG_FU_WU(1, "同城服务"),
    XIAN_SHANG_SHANG_CHENG(2, "线上商城"),
    TONG_CHENG_PEI_SONG(3, "同城配送");

    @Getter
    @Setter
    private Integer code;
    @Getter
    @Setter
    private String message;

    ShopTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getMessage(Integer code) {
        for (ShopTypeEnum item : ShopTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getMessage();
            }
        }
        return "";
    }

    public static Integer getCode(String message) {
        for (ShopTypeEnum item : ShopTypeEnum.values()) {
            if (item.getMessage().equals(message)) {
                return item.getCode();
            }
        }
        return -1;
    }

    public static ShopTypeEnum getByTypeAndAdcode(Integer code, String shopAdcode, String locationAdcode) {
        switch (code) {
            case 1:
                return ShopTypeEnum.TONG_CHENG_FU_WU;
            case 2:
                if (StringUtils.isNotBlank(shopAdcode) && shopAdcode.equals(locationAdcode)) {
                    return ShopTypeEnum.TONG_CHENG_PEI_SONG;
                } else {
                    return ShopTypeEnum.XIAN_SHANG_SHANG_CHENG;
                }
            default:
                return ShopTypeEnum.XIAN_SHANG_SHANG_CHENG;
        }
    }
}
